package cc.linker.steplink.crm.merchanth5.controller;

import cc.linker.steplink.crm.commons.domain.WxUser;
import cc.linker.steplink.crm.merchanth5.commons.RequestFilter;
import cc.linker.steplink.crm.merchanth5.pojo.TreatyPo;
import cc.linker.steplink.crm.merchanth5.service.TreatyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;



/**
 * 平台协议
 * @author huhj
 */

@RestController
@RequestMapping("/h5/treaty")
public class H5TreatyController {

    @Autowired
    private TreatyService treatyService;
    @Autowired
    private RequestFilter requestFilter;

    /**
     * 获取协议详情
     * @param treatyName 协议名称
     * @return
     * @throws Exception
     */
    @GetMapping("/gettreatyinfo")
    public TreatyPo getTreatyInfo(HttpServletRequest request, String treatyName) {
        WxUser wxUser =  requestFilter.getWxUser(request);
        String orgId = wxUser.getOrgId();
        Map<String, Object> param = new HashMap<>();
        param.put("treatyName", treatyName);
        param.put("orgId", orgId);
        return treatyService.getTreatyInfo(param);
    }

    /**
     * 获取用户阅读协议记录
     * @param request
     * @param treatyName
     * @return
     */
    @GetMapping("/getreadrecord")
    public Map<String,Object> getReadRecord(HttpServletRequest request,String treatyName){
        WxUser wxUser =  requestFilter.getWxUser(request);
        Map<String, Object> param = new HashMap<>();
        param.put("treatyName", treatyName);
        param.put("customerId", wxUser.getCustomerId());
        param.put("orgId", wxUser.getOrgId());
        return treatyService.getReadRecord(param);
    }

    /**
     * 保存用户阅读协议记录
     * @param request
     * @param param
     */
    @PostMapping("/addreadrecord")
    public void addReadRecord(HttpServletRequest request,@RequestBody Map<String, Object> param){
        WxUser wxUser =  requestFilter.getWxUser(request);
        param.put("customerId", wxUser.getCustomerId());
        param.put("orgId", wxUser.getOrgId());
        treatyService.addReadRecord(param);
    }

}
